import Layout from '@components/Layouts/Layout'; import PostPreview from '@components/PostPreview/PostPreview'; import { t } from '@lingui/macro'; import { NextPageWithLayout } from '@ts/types/app'; import { ThematicProps } from '@ts/types/taxonomies'; import { loadTranslation } from '@utils/helpers/i18n'; import { GetStaticPaths, GetStaticProps, GetStaticPropsContext } from 'next'; import { ParsedUrlQuery } from 'querystring'; import { ReactElement } from 'react'; import styles from '@styles/pages/Thematic.module.scss'; import { getAllThematicsSlug, getThematicBySlug, } from '@services/graphql/queries'; const Thematic: NextPageWithLayout = ({ thematic }) => { const getPostsList = () => { return thematic.posts.reverse().map((post) => (
  • )); }; return (

    {thematic.title}

    {thematic.posts.length > 0 && (

    {t`All posts in ${thematic.title}`}

      {getPostsList()}
    )}
    ); }; Thematic.getLayout = function getLayout(page: ReactElement) { return {page}; }; interface PostParams extends ParsedUrlQuery { slug: string; } export const getStaticProps: GetStaticProps = async ( context: GetStaticPropsContext ) => { const translation = await loadTranslation( context.locale!, process.env.NODE_ENV === 'production' ); const { slug } = context.params as PostParams; const thematic = await getThematicBySlug(slug); return { props: { thematic, translation, }, }; }; export const getStaticPaths: GetStaticPaths = async () => { const allSlugs = await getAllThematicsSlug(); return { paths: allSlugs.map((post) => `/thematique/${post.slug}`), fallback: true, }; }; export default Thematic;